home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.4 Applications 1997 August / SGI IRIX 6.4 Applications 1997 August.iso / dist / mmailp.idb / usr / lib / Zmail / samples / zscript / uniq.zsc.z / uniq.zsc
Encoding:
Text File  |  1997-01-22  |  2.0 KB  |  68 lines

  1. # Sample Z-Script  function: uniq
  2. #              button: Uniq
  3.  
  4. function uniq() {
  5. #%
  6. # Cull duplicate messages out of a folder.  Useful if you've saved the
  7. # same message more than once or merged together two folders that had
  8. # some overlap.  Removes duplicates of the argument message (e.g., the
  9. # selected message, if attached to a button in GUI mode).
  10. #
  11. # To apply this function to all the messages, just do:
  12. #
  13. #    each * uniq
  14. #%
  15. #
  16. # If you plan to use it that way regularly, you might check the comments
  17. # for suggestions on speeding it up.  See also "fastuniq".
  18. #
  19.     unset any same first    # Initialize variable state
  20.     set deleted=""
  21.     if $?1
  22.     msg_list - $1    # Set current message = first argument
  23.     else
  24.     msg_list - 1    # Set current message = first message
  25.     endif
  26.     if $status != 0
  27.     return
  28.     endif
  29.     #
  30.     # Get the deleted messages -- speeds up later operations.
  31.     # If .-$ is used in the pick range below, you can speed this
  32.     # up too by using:     msg_list .-$ | :d | set deleted
  33.     #
  34.     :d | set deleted
  35.     #
  36.     # If the current message is deleted, don't do anything
  37.     #
  38.     msg_list . { $deleted } | set any
  39.     if $?any == 0
  40.     return
  41.     endif
  42.     #
  43.     # Find all the messages with the same message-id as this message
  44.     # Restrict the pick to non-deleted messages for speed.  Faster
  45.     # still would be to replace * with .-$ (here to the end).
  46.     #
  47.     eval -h pick -r * { $deleted } -h message-id %i | set same
  48.     #
  49.     # If some of your messages don't have a message-id, you can apply
  50.     # this more time-consuming test (only in version 2.1 and later):
  51.     #
  52.     # eval -h pick -r .-$ { $deleted } -h date,subject %?date?, %?subject?
  53.     #
  54.     # Sanity check -- perhaps the header is missing?
  55.     #
  56.     if $?same
  57.     # Get the number of the first of the selected messages
  58.     pick +1 -r $same | set first
  59.     # Delete all the matches except that first message
  60.     delete $same { $first }
  61.     msg_list $first        # The "output" of uniq is $first
  62.     else
  63.     echo -p Skipping %m
  64.     endif
  65.     return 0
  66. }
  67. button -n Uniq uniq
  68.